﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lilium.T4.Hosting;
using System.Web;

namespace Lilium.Web.Mvc.T4
{
    public sealed class ContentDispositionProcessor : CustomDirectiveProcessorBase
    {
        public override void ProcessDirective(IDictionary<string, string> arguments)
        {
            if (arguments == null) throw new ArgumentNullException("arguments");

            var resultBuilder = new StringBuilder(GetRequiredArgument(arguments, "value"));
            string fileName;
            if (arguments.TryGetValue("fileName", out fileName))
                resultBuilder.Append("; filename=\"").Append(fileName).Append('"');
            
            HttpContext.Current.Response.AddHeader("Content-Disposition", resultBuilder.ToString());
        }
    }
}
